/*
 * @lc app=leetcode.cn id=868 lang=javascript
 *
 * [868] 二进制间距
 */

// @lc code=start
/**
 * @param {number} n
 * @return {number}
 */
var binaryGap = function (n) {
    n = n.toString(2)
    let max = 0
    let last
    for (let i = 0; i < n.length; i++) {
        if (n[i] == 1) {
            if (last !== undefined) {
                max = Math.max(max, i - last)
            }
            last = i
        }
    }
    return max
};
// @lc code=end

